package com.example.springbootmqtt.mqtt;

import com.hivemq.client.mqtt.lifecycle.MqttClientDisconnectedListener;
import com.hivemq.client.mqtt.mqtt5.Mqtt5Client;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.ssl.SslBundles;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;


@Slf4j
@Service
@RequiredArgsConstructor
public class MqttClientFactory {


    public Mqtt5Client createMqtt5Client(MqttClientDisconnectedListener mqttClientDisconnectedListener) {
        return Mqtt5Client.builder()
                .serverHost("localhost")
                .serverPort(1883)
                .addConnectedListener(context -> {
                    log.info("Connected to MQTT broker on: {}", context.getClientConfig().getServerAddress());
                })
                .addDisconnectedListener(mqttClientDisconnectedListener)
                .build();
    }


}
